import React, {PureComponent} from "react";
import {connect} from "react-redux";
import {Form} from "antd";
import {getVehicleFeesByClientId} from "./actions";
import FilterForm from "../../components/FilterForm";

class VehicleFeeFilter extends PureComponent {
    state = {};
    handleSearch = (values) => {
        const {dispatch, modelId} = this.props;
        let fields = values;
        this.setState({...fields});
        dispatch(getVehicleFeesByClientId({
            ...fields,
            'ownerId': modelId
        }));
    };

    render() {
        const {loading, filter} = this.props;
        const filterSchema = [
            {
                key: 'name',
                field: 'name',
                type: 'text',
                expandable: true,
                width: 200,
                title: '车型',
                fieldOptions: {
                    initialValue: filter.name
                }
            }, {
                key: 'startPlace',
                field: 'startPlace',
                type: 'text',
                expandable: true,
                width: 200,
                title: '起始地点',
                fieldOptions: {
                    initialValue: filter.startPlace
                }
            }, {
                key: 'endPlace',
                field: 'endPlace',
                type: 'text',
                expandable: true,
                width: 200,
                title: '目的地点',
                fieldOptions: {
                    initialValue: filter.endPlace
                }
            }
        ];

        return (
            <FilterForm schema={filterSchema} callback={this.handleSearch} loading={loading}/>
        );
    }
}

const mapStateToProps = state => {
    return {
        ...state.client.clientVehicleFee,
        modelId: state.client.modify.model.id
    };
};

export default connect(mapStateToProps)(Form.create()(VehicleFeeFilter));
